<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.util.*" %>
<%@ page import="com.sms.project.*" %>

<%	//清除内存
	response.setHeader("Pragma","No-cache"); 
	response.setHeader("Cache-Control","no-cache"); 
	response.setDateHeader("Expires", 0); 
%> 


<%
	request.setCharacterEncoding("utf-8");
	String userno = (String)session.getAttribute("userno");
	
	String row = request.getParameter("row");//获取该项目是第几行的参数(从0开始的)
	int num = Integer.parseInt(row);
	Project p = null;

	String progress = request.getParameter("progress");
	String condition = "";
	if(progress != null) {
		if(progress.trim().equals("already")) {
			condition = "finish";
		} else if(progress.trim().equals("unalready")){
			condition = "notfinish";
		} else {
			condition = "";
		}
	} else {
		condition = "";
	}

	//得到该项目的对象并赋值
	List<Project> plist = new ArrayList<Project>();
	plist = Task.getTProject(userno, condition);
	if(plist != null && plist.size() > 0) {
		p = (Project)plist.get(num);
	} else {
		return;
	}
	
	int proID = p.getProID();
	List<PTask> tlist1 = new ArrayList<PTask>();
	tlist1 = Task.getGTask(userno, proID);
	
	int totalRecords = 0;
	int totalPage = 0;
	int pageSize = 2;
	
	if(tlist1 != null && tlist1.size() > 0) {
		totalRecords = tlist1.size();
	}
	totalPage = (totalRecords + pageSize -1)/pageSize;
	
	if(totalPage < 1) {
		totalPage = 1;
	}
	int pageNo = 1;
	try {
		pageNo = Integer.parseInt(request.getParameter("pageNo"));
		if(pageNo < 1) {
			pageNo = 1;
		} else if(pageNo > totalPage) {
			pageNo = totalPage;
		}
	} catch(NumberFormatException e) {
		pageNo = 1;
	}
	int startPos = (pageNo -1)*pageSize;
	
	List<PTask> tlist = new ArrayList<PTask>();
	tlist = Task.getGTask(userno, proID, startPos, pageSize);
%>	

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
 <br/>
<span style="margin-left: 35px;"><b>项目名称：<%= p.getProName() %></b>&nbsp;&nbsp;</span>
<div  class="button"  style="margin:15px auto; width:600px;">
<a class="easyui-linkbutton" id="add-ptask" style=" margin-left:5px; margin-top:5px;" iconCls="icon-add">发布新任务</a>
<a class="easyui-linkbutton" id="cut-ptask" style=" margin-left:5px; margin-top:5px;" iconCls="icon-cut">删除任务</a>
<!--   任务接受者：
    <input id="receiver" name="toID" style="width:80px;" />
    <input id='submit'  type="submit" value="搜索"  />-->
</div>
	
    
<form  id="task">
<input type="hidden" name="action" value="delete"/>
<input type="hidden" name="row" id="row" value="<%= num %>"/>
<input type="hidden" name="progress" id="progress" value="<%= progress %>"/>
<input type="hidden" name="proID" id="proID" value="<%= proID %>"/>

<table class="project" cellpadding="0" cellspacing="0">
   <tr><th>任务接收者</th><th>发布日期</th><th>截止时间</th><th>状态</th><th>任务内容</th><th>附件</th><th>更改进度</th><th>是否删除</th></tr>
   
   <%
   if(tlist != null && tlist.size() != 0) {
   	for(int i=0; i<tlist.size(); i++) {
   		PTask pt = (PTask)tlist.get(i);
	%>
	<tr><td><%= pt.getToName() %></td><td><%= pt.getStartTime() %></td><td><%= pt.getEndTime()  %></td><td><%= (pt.getStatus().equals("1"))?"已完成":"未完成" %></td><td><%= pt.getContent() %></td>
   <td style="text-align:center;height:30px;" >
   <% 
     	List<Map> appendFile = null;
		//如果有附件
		if(pt.getIsAppend().equals("1")) {
			appendFile = new ArrayList<Map>();
			appendFile = pt.getAppendFile();
      		for(int j=0; j<appendFile.size(); j++) {
      				Map<String, String> map = (Map<String, String>)appendFile.get(j);
					String fileName = (String)map.get("fileName");
					String saveName = (String)map.get("saveName");
      %>
      			<a href="DownServlet?fileName=<%= fileName %>&saveName=<%= saveName %>"><%= fileName %></a>&nbsp;&nbsp;
      <%
      		}
      	} else {
      %>
      		无
      <%
      	}
      %> 
   </td>
   <td>更改进度</td>
   <td><input type="checkbox" id="delID" name="delID" value="<%=pt.getTaskID()  %>" /></td>
   </tr>
   <%
   	}
   }
   %>
</table>
</form>
<br/>
<p style="text-align:center;" id='page'>第<%= pageNo %>页
    <% 
    	if(pageNo != 1) {
    %>
    <a href="javascript:void(0)" onclick="jump(<%= pageNo -1 %>);">上一页</a>
    <%}%>
    <% 
    	if(totalPage == 0) {
    		totalPage = 1;
    	}
    %>
   	<%
   		if(pageNo != totalPage) { 
   	%>
    		<a href="javascript:void(0)" onclick="jump(<%= pageNo + 1 %>);">下一页</a> 
    <% } %>
    	&nbsp;&nbsp;&nbsp;
    	共<%= totalPage %>页</p>  
<div id="another"></div>
<script type="text/javascript">
/*搜索处理,搜索按钮没有写，没有传数据*/
//var word;
/*$("#searchType option:eq(0)").click(function(){
	$('#word').datebox({
		editable:false,
		formatter:function(date){
			return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
			}
			})
//	word=$('#word').datebox('getValues');
	})*/	
	
/*$("#receiver").combobox({
	multiple:false,
	url:'GetStudentServlet',
	valueField:"sno",  
    textField:"sname"  
    
})*/	
/*var data = $('#receiver').combobox('getData');
$("#receiver").combobox('setValue',data[0]);
	*/
$("#cut-ptask").click(function(){
	if(confirm('确定删除吗')){
	$.ajax({
		url:'project/teacher/del-task.jsp',   /*记得添加处理页面*/
		data:$("#task").serialize(),
		dataType:'text',
		success:function(msg){
			  if(msg=='ok'){
				 alert('修改成功');
				 $('#dd').dialog('refresh','project/teacher/manage-task.jsp?row='+$('#row').attr('value') + '&progress=' + $('#progress').attr('value'));
				  }
			else {
				alert("修改失败");
			}                      
			}
		})
		}
	})  
function jump(i) {
	$('#dd').dialog('refresh','project/teacher/manage-task.jsp?row=' + $('#row').attr('value') + '&progress=' + $('#progress').attr('value') + '&pageNo=' + i);
}
$("#add-ptask").click(function(){
	$('#another').dialog({
			         title:"添加项目任务",
					 width:1000, height:600,
					 top:150,left:100,
					 resizable:true,
					 cache:false,
					 href:'project/teacher/add-task.jsp?proID=' + $('#proID').attr('value')
					 });
			
	})	
</script>
</body>
</html>
